'\" te
.\" Copyright (c) 2008, Sun Microsystems, Inc.  All Rights Reserved.
.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
.\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
.TH AIOWAIT 3C "Feb 5, 2008"
.SH NAME
aiowait \- wait for completion of asynchronous I/O operation
.SH SYNOPSIS
.LP
.nf
#include <sys/asynch.h>
#include <sys/time.h>

\fBaio_result_t *\fR\fBaiowait\fR(\fBconst struct timeval *\fR\fItimeout\fR);
.fi

.SH DESCRIPTION
.sp
.LP
The \fBaiowait()\fR function suspends the calling process until one of its
outstanding asynchronous I/O operations completes, providing a synchronous
method of notification.
.sp
.LP
If \fItimeout\fR is a non-zero pointer, it specifies a maximum interval to wait
for the completion of an asynchronous I/O operation. If \fItimeout\fR is a zero
pointer, \fBaiowait()\fR blocks indefinitely.  To effect a poll, the
\fItimeout\fR parameter should be non-zero, pointing to a zero-valued
\fItimeval\fR structure.
.sp
.LP
The \fBtimeval\fR structure is defined in <\fBsys/time.h\fR> and contains the
following members:
.sp
.in +2
.nf
long  tv_sec;           /* seconds */
long  tv_usec;          /* and microseconds */
.fi
.in -2

.SH RETURN VALUES
.sp
.LP
Upon successful completion, \fBaiowait()\fR returns a pointer to the result
structure used when the completed asynchronous I/O operation was requested.
Upon failure, \fBaiowait()\fR returns \fB\(mi1\fR and sets \fBerrno\fR to
indicate the error. \fBaiowait()\fR returns \fB0\fR if the time limit expires.
.SH ERRORS
.sp
.LP
The \fBaiowait()\fR function will fail if:
.sp
.ne 2
.na
\fB\fBEFAULT\fR\fR
.ad
.RS 10n
The \fItimeout\fR argument points to an address outside the address space of
the requesting process.  See \fBNOTES\fR.
.RE

.sp
.ne 2
.na
\fB\fBEINTR\fR\fR
.ad
.RS 10n
The execution of \fBaiowait()\fR was interrupted by a signal.
.RE

.sp
.ne 2
.na
\fB\fBEINVAL\fR\fR
.ad
.RS 10n
There are no outstanding asynchronous I/O requests.
.RE

.sp
.ne 2
.na
\fB\fBEINVAL\fR\fR
.ad
.RS 10n
The \fBtv_secs\fR member of the \fBtimeval\fR structure pointed to by
\fItimeout\fR is less than 0 or the \fBtv_usecs\fR member is greater than the
number of seconds in a microsecond.
.RE

.SH ATTRIBUTES
.sp
.LP
See \fBattributes\fR(7) for descriptions of the following attributes:
.sp

.sp
.TS
box;
c | c
l | l .
ATTRIBUTE TYPE	ATTRIBUTE VALUE
_
MT-Level	Safe
.TE

.SH SEE ALSO
.sp
.LP
.BR aiocancel (3C),
.BR aioread (3C),
.BR attributes (7)
.SH NOTES
.sp
.LP
The \fBaiowait()\fR function is the only way to dequeue an asynchronous
notification. It can be used either inside a \fBSIGIO\fR signal handler or in
the main program. One \fBSIGIO\fR signal can represent several queued events.
.sp
.LP
Passing an illegal address as \fItimeout\fR will result in setting \fBerrno\fR
to \fBEFAULT\fR only if detected by the application process.
